<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="860" title="对接设置">
        <Form :model="data" :label-width="100" :rules="ruleValidate" ref="formCreate">
            <FormItem label="耗材名称" prop="name">
                <Input v-model="data.name"></Input>
            </FormItem>
            <FormItem label="耗材售价" prop="price">
                <Input v-model="data.price" number></Input>
            </FormItem>
            <Row>
                <Col :span="8">
                    <FormItem label="长" prop="length">
                        <Input v-model="data.length" number></Input>
                    </FormItem>
                </Col>
                <Col :span="8">
                    <FormItem label="宽" prop="width">
                        <Input v-model="data.width" number></Input>
                    </FormItem>
                </Col>
                <Col :span="8">
                    <FormItem label="高" prop="height">
                        <Input v-model="data.height" number></Input>
                    </FormItem>
                </Col>
            </Row>
            <FormItem label="耗材毛重" prop="weight">
                <Input v-model="data.weight" number></Input>
            </FormItem>
            <FormItem label="耗材说明" prop="remark">
                <Input v-model="data.remark" type="textarea" :rows="4"></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false;">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IForm from "../../../components/content/form";
    import contentDrawer from "../../../mixins/contentDrawer";
    import IDrawer from "../../../components/content/drawer";
    import IData from "./data";
    import RemoteSelect from "../../../components/form/remoteSelect";

    export default {
        name: "update",
        mixins: [contentDrawer, IData],
        components: {RemoteSelect, IForm, IDrawer},
        data() {
            return {}
        },
        mounted(){
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                this.$http.get(`warehouse/consumable/${this.props.id}/edit`).then((res) => {
                    this.data = res;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit(data) {
                this.validate(data).then(() => {
                    this.loading = true;
                    this.$http.put(`warehouse/consumable/${this.props.id}`, this.data).then(() => {
                        this.getData();
                    }).finally(() => {
                        this.loading = false;
                    });
                });
            }
        }
    }
</script>

<style scoped>

</style>
